<?php
/**
 * Gallery Add Image
 *
 * @package Bd Gallery
 * @author Bebliuc George Cristian
 * @author Gianfranco Liporace
 * @copyright 2008-2010
 * @version 1.3
 * @access public
 * @permisions Modify, Redistribute but leave the credits alive :P
 * @use Noncommercial, for commercial use, please contact me at bebliuc.george@gmail.com, it's for free, but I need to know
 *
 */

$photo_upload_fields = '';
$photo_category_list = '';
$counter = 1;
if (array_key_exists('number_of_fields', $_POST)) {
    $number_of_fields = $_POST['number_of_fields'];
} else {
    $number_of_fields = 1;
}

$categories = Category::findAllFrom('category');
foreach($categories as $category)
    $photo_category_list .= "<option value=\"$category->id\">$category->category_name</option>\n";

while ($counter <= $number_of_fields) {
    $photo_upload_fields .= '
<p class="title">
<label for="photo_title">'. __('Title') .'</label>
<input type="text" name="photo_title[]" value="" class="textbox"><br />
<label for="photo_filename">'. __('Photo') .' '.$counter.':</label>
<input name="photo_filename[]" type="file" /><br />
<label for="photo_caption">'. __('Description') .':</label>
<textarea name="photo_caption[]" cols="30" class="textarea" rows="1"></textarea>
<br />
<hr />
<br />
</p>
';
    $counter++;
}
?>
<a href="<?php echo get_url('plugin/gallery/add_image'); ?>#" onclick="toggle_popup('number_of_fields'); return false;" title="Add more upload fields"><img src="<?php echo GALLERY_ROOT; ?>/images/more.png" /><?php echo __('More upload fields'); ?></a><br /><br />
<?php
echo '
<form enctype="multipart/form-data" action="'. get_url('plugin/gallery/upload_image') . '" method="post" name="upload_form">
<div class="form-area">
<p class="title">
<label for="category">'. __('Category') .'</label>
<select name="category">' . $photo_category_list . '</select>
</p><br /><br />
' . $photo_upload_fields . '

<p class="buttons">
<input type="submit" class="button" name="submit" size="50" value="'. __('Add Photos') .'" />
</p>
</form>
</div>
';
?>
<div id="popups">
    <div class="popup" id="number_of_fields" style="display:none;">
        <h3><?php echo __("Number of upload fields"); ?></h3>
        <form method="post" name="upload_numeber" action="<?php echo get_url('plugin/gallery/add_image'); ?>">
            <input type="text" value="<?php echo $number_of_fields; ?>" name="number_of_fields" class="textbox" /><br />
            <input type="submit" value="<?php echo __("Add fields"); ?>" />
        </form>
        <p><a class="close-link" href="#" onclick="Element.hide('number_of_fields'); return false;"><?php echo
__('Close'); ?></a></p>
    </div>
</div>